PROJECT(znx)
CMAKE_MINIMUM_REQUIRED(VERSION 3.0)

# ADD_DEFINITIONS(-DZNX_MEM_NO_POOL)
# ADD_DEFINITIONS(-DZNX_THREAD_MEM_NO_POOL)
# ADD_DEFINITIONS(-DZNX_POOL_NO_PAGE)

SET(CMAKE_C_COMPILER "clang-11")
SET(LINK_FLAGS "${LINK_FLAGS} -rdynamic")


SET(C_FLAGS
    " -Wall"
    " -Wextra"
    " -Werror"
    " -Wno-unused-parameter"
    " -Wconversion"
    " -march=native"
    " -std=gnu11"
    " -ggdb"
    " -fstack-protector"
    " --param=ssp-buffer-size=4"
)

MESSAGE(${C_FLAGS})


IF(BUILD_TYPE STREQUAL "release")
    SET(C_FLAGS
	"${C_FLAGS}"
	" -O2")

ELSEIF(BUILD_TYPE STREQUAL "debug")
    SET(C_FLAGS
	"${C_FLAGS}"
	" -O0")

ELSE()
    SET(C_FLAGS
	"${C_FLAGS}"
	" -fsanitize=address"
	" -fno-omit-frame-pointer"
	" -O0")
ENDIF()


STRING(REPLACE ";" " " CMAKE_C_FLAGS "${C_FLAGS}")
MESSAGE(C_FLAGS ": " ${CMAKE_C_FLAGS})

INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/src)

INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/libs/openssl/include/)

INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/libs/yaml/include/)

# add modules
SET(MODULES_SRC "")
INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/modules)
INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/obj)
ADD_SUBDIRECTORY(obj)

MESSAGE(MODULES_SRC ": " ${MODULES_SRC})

ADD_SUBDIRECTORY(src)
ADD_SUBDIRECTORY(test)
